import time
import redis
from celery import Celery

r = redis.Redis(host="127.0.0.1", port=6379, password="myredis")

BROKER_URL = 'redis://:myredis@localhost:6379/0'
BACKEND_URL = 'redis://:myredis@localhost:6379/0'
celery_app = Celery('tasks', broker=BROKER_URL, backend=BACKEND_URL)

@celery_app.task(bind=True)
def task_demo(self):

    current_task_id = self.request.id
    
    for i in range(100):
        time.sleep(1)
        r.set(f'task-progress-{current_task_id}', (i+1) / 100)

    return {
        'task_id': current_task_id
    }


'''celery -A tasks worker --loglevel=INFO --pool=eventlet --concurrency=5'''